package org.jeecg.modules.api.common.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.jetbrains.annotations.NotNull;

import java.time.*;

@Accessors(chain = true)
@Data
@ApiModel(value = "日期折线图VO对象")
public class DateLineChartVO implements Comparable<DateLineChartVO> {

    @ApiModelProperty(value = "标记")
    private String mark;
    @ApiModelProperty(value = "数值")
    private Number num;
    @ApiModelProperty(value = "时间")
    private LocalTime time;
    // @JsonFormat(timezone = "GMT+8", pattern = "yyyy年MM月dd日")
    //@DateTimeFormat(pattern = "yyyy年MM月dd日")
    @ApiModelProperty(value = "日期")
    private LocalDate date;
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    //@DateTimeFormat(pattern = "yyyy年MM月dd日 HH:mm:ss")
    @ApiModelProperty(value = "日期时间")
    private LocalDateTime dateTime;
    @ApiModelProperty(value = "时间戳")
    private Long timeseries;

    @JsonFormat(timezone = "GMT+8", pattern = "MM-dd")
    @ApiModelProperty(value = "日期（不包含年份）")
    public LocalDate getDateWithNoYear() {
        return date;
    }


    public DateLineChartVO setDateTime(LocalDateTime dateTime) {
        this.dateTime = dateTime;
        this.date = dateTime == null ? null : dateTime.toLocalDate();
        this.time = dateTime == null ? null : dateTime.toLocalTime();
        this.timeseries = dateTime == null ? null : dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        return this;
    }

    @Override
    public int compareTo(@NotNull DateLineChartVO o) {
        return this.dateTime.compareTo(o.getDateTime());
    }
}
